import request from '@/utils/requestLogin'

export interface Photo {
    id: number
    url: string
    category: string
    isPrivate: boolean
    description: string
    order: number
    createTime: string
    updateTime: string
}

export interface PhotoForm {
    url: string
    category: string
    isPrivate: boolean
    password?: string
    description: string
    order?: number
}

interface ApiResponse<T> {
    code: number
    message: string
    data: T
}

export interface PhotoListResponse {
    list: Photo[]
    total: number
    page: number
    pageSize: number
    hasMore: boolean
}

export interface PhotoListParams {
    page: number
    pageSize: number
    password?: string
}

// 添加代理配置
const API_BASE_URL = 'http://cylyxsz.w1.luyouxia.net'

export const photoApi = {
    // 前台获取照片列表
    getPublicPhotoList: (params: PhotoListParams) => {
        return request.get<PhotoListResponse>(`${API_BASE_URL}/blog/api/photos`, params )
    },

    // 后台管理获取照片列表
    getAdminPhotoList: (params: PhotoListParams) => {
        return request.get<PhotoListResponse>('http://cylyxsz.w1.luyouxia.net/blog/api/admin/photos', params )
    },

    // 添加照片
    addPhoto(data: PhotoForm) {
        return request.post<ApiResponse<Photo>>('http://cylyxsz.w1.luyouxia.net/blog/api/photos', data)
    },

    // 更新照片
    updatePhoto(id: number, data: PhotoForm) {
        return request.put<ApiResponse<Photo>>(`http://cylyxsz.w1.luyouxia.net/blog/api/photos/${id}`, data)
    },

    // 删除照片
    deletePhoto(id: number) {
        return request.delete<ApiResponse<any>>(`http://cylyxsz.w1.luyouxia.net/blog/api/photos/${id}`)
    }
} 